package com.Pawtrack.web.controller.info;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.Pawtrack.common.annotation.Log;
import com.Pawtrack.common.annotation.DataScope;
import com.Pawtrack.common.core.controller.BaseController;
import com.Pawtrack.common.core.domain.AjaxResult;
import com.Pawtrack.common.enums.BusinessType;
import com.Pawtrack.info.domain.PetHealth;
import com.Pawtrack.info.service.IPetHealthService;
import com.Pawtrack.common.utils.poi.ExcelUtil;
import com.Pawtrack.common.core.page.TableDataInfo;
import com.Pawtrack.common.utils.SecurityUtils;

/**
 * 宠物健康Controller
 * 
 * @author ruoyi
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/system/health")
public class PetHealthController extends BaseController
{
    @Autowired
    private IPetHealthService petHealthService;

    /**
     * 查询宠物健康列表
     */
    @GetMapping("/list")
    @DataScope(deptAlias = "p", userAlias = "p")
    public TableDataInfo list(PetHealth petHealth)
    {
        startPage();
        List<PetHealth> list = petHealthService.selectPetHealthList(petHealth);
        return getDataTable(list);
    }

    /**
     * 导出宠物健康列表
     */
    @Log(title = "宠物健康", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetHealth petHealth)
    {
        List<PetHealth> list = petHealthService.selectPetHealthList(petHealth);
        ExcelUtil<PetHealth> util = new ExcelUtil<PetHealth>(PetHealth.class);
        util.exportExcel(response, list, "宠物健康数据");
    }

    /**
     * 获取宠物健康详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(petHealthService.selectPetHealthById(id));
    }

    /**
     * 新增宠物健康
     */
    @Log(title = "宠物健康", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetHealth petHealth)
    {
        // 设置创建人为当前用户ID
        petHealth.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return toAjax(petHealthService.insertPetHealth(petHealth));
    }

    /**
     * 修改宠物健康
     */
    @Log(title = "宠物健康", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetHealth petHealth)
    {
        // 设置更新人为当前用户ID
        petHealth.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
        return toAjax(petHealthService.updatePetHealth(petHealth));
    }

    /**
     * 删除宠物健康
     */
    @Log(title = "宠物健康", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(petHealthService.deletePetHealthByIds(ids));
    }
}
